<template>
  <el-dialog
    :title="'输入数据'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="网关号" prop="gwsn" class="input-container">
        <el-input v-model="dataForm.gwsn" placeholder="网关号" :readonly="true"></el-input>
      </el-form-item>
<!--      <el-form-item label="直径" prop="silkDiameter" class="input-container">-->
<!--        <el-input v-model="dataForm.silkDiameter" placeholder="直径"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="直径" prop="silkDiameter">
        <el-select v-model="dataForm.silkDiameter" placeholder="请选择直径">
          <el-option label="1.2" value="1.2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="融化率" prop="silkMeltrate">
        <el-select v-model="dataForm.silkMeltrate" placeholder="请选择融化率">
          <el-option label="0.1" value="0.1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工时" prop="theoWorkTime">
        <el-select v-model="dataForm.theoWorkTime" placeholder="请选择工时">
          <el-option label="8" value="8"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="暂停率" prop="pauseRate">
        <el-select v-model="dataForm.pauseRate" placeholder="请选择暂停率">
          <el-option label="0.6" value="0.6"></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="融化率" prop="silkMeltrate" class="input-container">-->
<!--        <el-input v-model="dataForm.silkMeltrate" placeholder="融化率"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="工时" prop="theoWorkTime" class="input-container">-->
<!--        <el-input v-model="dataForm.theoWorkTime" placeholder="工时"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="暂停率" prop="pauseRate" class="input-container">-->
<!--        <el-input v-model="dataForm.pauseRate" placeholder="暂停率"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
          v-model="dataForm.startDate"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
          class="date-picker-container">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
          v-model="dataForm.endDate"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
          class="date-picker-container">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <!--      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>-->
      <el-button type="primary" @click="sub()">确定</el-button>
    </span>

    <el-dialog
      width="50%"
      title="利用率"
      :visible.sync="innerVisible"
      append-to-body>
      <el-table
        :data="userateList"
        border
        ref="singleTable"
        highlight-current-row
        :header-cell-style="{background:'#17b3a3',color:'#FFFFFF'}"
        style="width: 100%;">
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50">
        </el-table-column>
        <el-table-column
          prop="wmNo"
          header-align="center"
          align="center"
          label="设备编号">
        </el-table-column>
        <el-table-column
          prop="actNum"
          header-align="center"
          align="center"
          label="实采数据量">
        </el-table-column>
        <el-table-column
          prop="actEffeNum"
          header-align="center"
          align="center"
          label="有效数据量">
        </el-table-column>
        <el-table-column
          prop="silkFeedSpeed"
          header-align="center"
          align="center"
          label="送丝速度">
        </el-table-column>
        <el-table-column
          prop="actHour"
          header-align="center"
          align="center"
          label="焊接时间">
        </el-table-column>
      </el-table>
<!--      <div>-->
<!--        <div v-for="userate in userateList" :key="userate.wmNo">-->
<!--          <p>WM No: {{ userate.wmNo }}</p>-->
<!--          <p>GWSN: {{ userate.gwsn }}</p>-->
<!--          <p>Start Date: {{ userate.startDate }}</p>-->
<!--          <p>End Date: {{ userate.endDate }}</p>-->
<!--          &lt;!&ndash; 显示其他字段 &ndash;&gt;-->
<!--        </div>-->
<!--      </div>-->
    </el-dialog>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        userateList:[],
        outerVisible: false,
        innerVisible: false,
        visible: false,
        dataForm: {
          gwsn: '',
          startDate: '',
          endDate: '',
          silkDiameter: '',
          silkMeltrate: '',
          theoWorkTime: '',
          pauseRate: ''
        },
        dataRule: {
          gwsn: [
            { required: true, message: 'gwSN不能为空', trigger: 'blur' }
          ],
          startDate: [
            { required: true, message: 'startDate不能为空', trigger: 'blur' }
          ],
          endDate: [
            { required: true, message: 'endDate不能为空', trigger: 'blur' }
          ],
          silkDiameter: [
            { required: true, message: 'silkDiameter不能为空', trigger: 'change' }
          ],
          silkMeltrate: [
            { required: true, message: 'silkMeltrate不能为空', trigger: 'blur' }
          ],
          theoWorkTime: [
            { required: true, message: 'worktime不能为空', trigger: 'blur' }
          ],
          pauseRate: [
            { required: true, message: 'pauseRate不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      sub(){
        console.log(this.dataForm)
        this.innerVisible = true;
        console.log("这是第三层")
        console.log(this.dataForm)

        this.$http({
          url: this.$http.adornUrl(`/weldingmachine/weldingmachine/userate`),
          method: 'get',
          params: this.$http.adornParams({
            'gwsn': this.dataForm.gwsn,
            'startDate': this.dataForm.startDate,
            'endDate': this.dataForm.endDate,
            'silkDiameter': this.dataForm.silkDiameter,
            'silkMeltrate': this.dataForm.silkMeltrate,
            'theoWorkTime': this.dataForm.theoWorkTime,
            'pauseRate': this.dataForm.pauseRate
          })
        }).then(({data}) => {
          console.log("这是返回的数据")
          console.log(data)
          this.userateList = data;
        })
      },
      init (id) {
        this.dataForm.wmname = id || 0
        this.visible = true
        console.log("刚进来")
        console.log(this.dataForm.wmname)
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.wmname) {
            this.$http({
              url: this.$http.adornUrl(`/weldingmachineinfo/weldingmachineinfo/getGwsn`),
              method: 'get',
              params: this.$http.adornParams({
                'wmId': this.dataForm.wmname
              })
            }).then(({data}) => {
              console.log(data)
              if (data) {
                this.dataForm.gwsn = data
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/weldradio/weldradio/${!this.dataForm.wmid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'wmid': this.dataForm.wmid || undefined,
                'wmname': this.dataForm.wmname,
                'onhour': this.dataForm.onhour,
                'workhour': this.dataForm.workhour,
                'weldingradio': this.dataForm.weldingradio,
                'errortimes': this.dataForm.errortimes,
                'unnormaltimes': this.dataForm.unnormaltimes,
                'powerdec': this.dataForm.powerdec,
                'remdec': this.dataForm.remdec,
                'pgmdec': this.dataForm.pgmdec,
                'wmtime': this.dataForm.wmtime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped>
.input-container {
  width: 280px; /* 调整宽度值以匹配你的需求 */
}

.date-picker-container {
  width: 200px; /* 调整宽度值以匹配你的需求 */
}
</style>
